package com.arcvideo.acsplayer.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;

import com.arcvideo.acsplayer.R;

public class ProgressDialog extends Dialog {
	private Context context = null;
	private static ProgressDialog progressDialog = null;

	public ProgressDialog(Context context) {
		super(context);
		this.context = context;
	}

	public ProgressDialog(Context context, int theme) {
		super(context, theme);
	}

	public static ProgressDialog createDialog(Context context) {
		progressDialog = new ProgressDialog(context, R.style.CustomProgressDialog);
		progressDialog.setContentView(R.layout.dialog_progress);
		progressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

		return progressDialog;
	}

	public void onWindowFocusChanged(boolean hasFocus) {

		if (progressDialog == null) {
			return;
		}

		ImageView imageView = (ImageView) progressDialog.findViewById(R.id.loadingImageView);
		AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
		animationDrawable.start();
	}

	/**
	 *
	 * [Summary] setTitile 标题
	 *
	 * @param strTitle
	 * @return
	 *
	 */
	public ProgressDialog setTitile(String strTitle) {
		return progressDialog;
	}

	/**
	 *
	 * [Summary] setMessage 提示内容
	 *
	 * @param strMessage
	 * @return
	 *
	 */
	public ProgressDialog setMessage(String strMessage) {
		TextView tvMsg = (TextView) progressDialog.findViewById(R.id.id_tv_loadingmsg);

		if (tvMsg != null) {
			tvMsg.setText(strMessage);
		}

		return progressDialog;
	}
}